#include <bits/stdc++.h>

using namespace std;
typedef long long LL;
int main_1037()
{
    int Nc,Np;
    scanf("%d",&Nc);
    LL NC[Nc]= {0};
    for (int i=0; i<Nc ; ++i )
    {
        scanf("%llu",&NC[i]);
    }
    scanf("%d",&Np);
    LL NP[Np]= {0},maxAmount=0;
    for (int i=0; i<Np ; ++i )
    {
        scanf("%llu",&NP[i]);
    }
    sort(NC,NC+Nc);
    sort(NP,NP+Np);
    LL i=0,j=0;
    while (i<Nc&&j<Np&&NC[i]<0&&NP[j]<0)
    {
        maxAmount+=NC[i]*NP[j];
        ++i,++j;
    }
    i=Nc-1;
    j=Np-1;
    while (i>=0&&j>=0&&NC[i]>0&&NP[j]>0)
    {
        maxAmount+=NC[i]*NP[j];
        --i,--j;
    }
    printf("%llu",maxAmount);
    return 0;
}
